#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
from pytools import mysqltool


def get_table_prefix():
    conn = mysqltool.connect_to_base_dicts()
    q = 'select distinct table_prefix from channel_define'
    return mysqltool.get_a_list_of_string(conn, q)


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'usage: %s month' % (sys.argv[0])
        sys.exit(0)

    prefix = get_table_prefix()
    table2drop = []
    for analy in ['detail_analytics', 'list_analytics']:
        xx = ['%s_%s_%s' % (pre, analy, sys.argv[1]) for pre in prefix]
        table2drop += xx
        table2drop.append('summary_%s' % (analy))
        table2drop.append('city_%s_%s' % (analy, sys.argv[1]))

    conn = mysqltool.connect_to_58_stats()
    for table in table2drop:
        print table
        mysqltool.droptable(conn, table)

